/*年轻人，只管向前看，不要管自暴自弃者的话*/
package com.composetest.ui.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.composetest.page.main.TopLevelDestination
import com.composetest.ui.theme.SpacerH5

/**
 * create by itz on 2024/10/12 9:31
 * desc :
 **/

@Composable
fun MyNavigationBar(
    destinations: List<TopLevelDestination>,
    onNavigationToDestination: (Int) -> Unit,
    currentDestination: String,
    modifier: Modifier = Modifier
): Unit {
    Row(
        modifier = modifier
            .fillMaxWidth()
            .background(Color.White)
            .navigationBarsPadding()
    ) {
        destinations.forEachIndexed { index, destination ->
            val selected = destination.route == currentDestination
            val color =
                if (selected) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface
            Column(
                horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier
                    .weight(1f)
                    .clickable { onNavigationToDestination(index) }
                    .padding(7.dp)
            ) {
                Image(
                    painter = painterResource(id = if (selected) destination.selectedIcon else destination.unselectedIcon),
                    contentDescription = null,
                    modifier = Modifier.size(23.dp)
                )
                SpacerH5()
                Text(
                    text = stringResource(id = destination.titleTextId),
                    style = MaterialTheme.typography.bodySmall,
                    color = color
                )
            }
        }
    }
}